import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-11-20
 * Time: 8:10
 */
public class Test {
    public static int res1;
    public static int res2;
    public static int i;
    public static void dfs(String s, int dep1,int dep2){
        res1=Math.max(res1,dep1);
        res2=Math.max(res2,dep2);
        int cnt = 0;
        while(i < s.length()){
            if(s.charAt(i)=='d'){
                i++;
                dfs(s,dep1+1,dep2+cnt+1); //dep2就是父节点的高度 + 左兄弟数+1
                cnt++;  //记录的已经有的dfs分支 也就是左兄弟
            }
            else{
                i++;
                return;
            }
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] arr = new String[100];
        String s = in.nextLine();
        int l = 0;
        while (!s.equals("#")) {
            arr[l++] = s;
            s = in.nextLine();
        }
        for (int j = 0; j < l; j++){
                res1 = -1;
                res2 = -1;
                i = 0;
                dfs(arr[j],0, 0);
                System.out.println("Tree " + (j + 1) +": " + res1 + " => " + res2);
        }
    }
}
